package zut.edu.cn.concertticketmanagementsystem.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zut.edu.cn.concertticketmanagementsystem.entity.AdminUser;
import zut.edu.cn.concertticketmanagementsystem.entity.User;
import zut.edu.cn.concertticketmanagementsystem.service.AdminUserService;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * User: cyl
 * Date: 2019/6/24
 * Time: 14:15
 * Description: No Description
 */
@Controller
public class AdminUserController {
    //得到一个用来记录日志的对象，这样打印信息的时候能够标记打印的是那个类的信息
    private static final Log logger = LogFactory.getLog(UserController.class);
    //将服务依赖注入到属性adminUserservice
    @Autowired
    public AdminUserService adminUserService;

    /**
     * 处理登录
     */
    @RequestMapping("/log")
    public String login2(AdminUser adminUser, HttpSession session, Model model) {
        if (adminUserService.login2(adminUser)) {
            session.setAttribute("u", adminUser);
            logger.info("成功");
            return "adminsuccess";
        } else {
            logger.info("失败");
            model.addAttribute("messageError", "用户名或密码错误");
            return "adminlogin";
        }
    }

    @PostMapping(value = "/all")
    public String All(AdminUser adminUser, HttpSession session, Model model) {

        return  "redirect:/list";

    }
}
